"ui";
var color = "#009688";
//开始时间，提前时间量，提交频率，结束时间，网络时间偏移，网络接口延迟，设备延迟，辅助提交，倒计时浮窗x，倒计时浮窗y
var startTime, forwardTime, interval, lastTime, NTPClockOffset, NTPClockDelay, deviceDelay, autoSubmit, xp, yp;
//自动购买，自动确认，自动结算，自动提交，自动支付，校验价格，最大价格，使用网络时间
var autoBuy, autoConfirm, autoCart, autoSubmit, autoPay, checkSku, needConfirm, checkPrice, maxPrice, isUseNetTime;
//捡漏，频率
var jlModel, jlhz;
//商品名称，购买按钮
var itemName, buyName, color, size, other, volume, type, skuNum = 0, skuDelay;



//倒计时浮窗
var window;
//定时任务
var workId;
//存储
var storage = storages.create("tb_qg.js");
//时间工具类
var timeUtils = require('./qg/TimeUtils.js');
var mModule = require('qxz.js');

var myQueue = new ArrayQueue();

importClass(android.view.View);

//主页面
ui.layout(
    <drawer id="drawer">
        <vertical>
            <appbar>
                <toolbar id="toolbar" title="详情页倒计时模式" />
                <tabs id="tabs" />
            </appbar>

            <viewpager id="viewpager">
                <frame>
                    <ScrollView>
                        <vertical w="*" h="auto" margin="6" >
                            <text h="30" id="networkTest" text="正在检测网络延迟..." gravity="top|left" textColor="red" textSize="13sp" margin="0 5" />
                            <horizontal>
                                <checkbox id="isUseNetTime" text="使用网络时间" textColor="black" checked="true" />
                                <checkbox id="autoPay" text="自动支付" checked="true" />
                            </horizontal>
                            <horizontal>
                                <checkbox id="needConfirm" text="需要确认" checked="true" />
                                <checkbox id="checkSku" text="sku延时：" checked="true" />
                                <input id="skuDelay" text="120" hint="120" marginBottom="-6" />
                            </horizontal>
                            <horizontal >
                                <checkbox id="checkPrice" text="最高价格：" textColor="black" />
                                <input id="maxPrice" text="" hint="10" marginBottom="-6" />
                            </horizontal>
                            <frame w="*" margin="12" h="1" bg="#e3e3e3" />
                            <horizontal >
                                <checkbox id="baseTime" text="倒计时    " textColor="black" />
                                <text h="30" text="X：" gravity="top|left" textColor="black" />
                                <input id="xp" text="360" hint="360" marginBottom="-6" />
                                <text h="30" text=" , Y：" gravity="top|left" textColor="black" />
                                <input id="yp" text="1250" hint="1250" marginBottom="-6" />
                            </horizontal>
                            <frame w="*" margin="12" h="1" bg="#e3e3e3" />
                            <horizontal >
                                <text h="30" text="商品关键字：" gravity="top|left" textColor="black" textSize="16" />
                                <input id="itemName" text="" hint="袋鼠医用" marginBottom="-6" />
                            </horizontal>
                            <horizontal >
                                <text h="30" text="购买关键字：" gravity="top|left" textColor="black" textSize="16" />
                                <input id="buyName" text="" hint="立即购买、领劵购买、马上抢" marginBottom="-6" />
                            </horizontal>
                            <vertical id="skuShow" >
                                <horizontal >
                                    <text h="30" text="颜色：" gravity="top|left" textColor="black" textSize="16" />
                                    <input id="color" text="" hint="颜色|颜色分类|机身颜色" marginBottom="-6" textSize="16" />
                                </horizontal>
                                <horizontal >
                                    <text h="30" text="尺码：" gravity="top|left" textColor="black" textSize="16" />
                                    <input id="size" text="" hint="尺码|鞋码|机身尺码" marginBottom="-6" textSize="16" />
                                </horizontal>
                                <horizontal >
                                    <text h="30" text="容量：" gravity="top|left" textColor="black" textSize="16" />
                                    <input id="volume" text="" hint="存储容量|化妆品净含量" marginBottom="-6" textSize="16" />
                                </horizontal>
                                <horizontal >
                                    <text h="30" text="类型：" gravity="top|left" textColor="black" textSize="16" />
                                    <input id="type" text="" hint="网络类型" marginBottom="-6" textSize="16" />
                                </horizontal>
                                <horizontal >
                                    <text h="30" text="其他：" gravity="top|left" textColor="black" textSize="16" />
                                    <input id="other" text="" hint="口味|套餐类型" marginBottom="-6" textSize="16" />
                                </horizontal>
                            </vertical>
                            <frame w="*" margin="12" h="1" bg="#e3e3e3" />
                            <horizontal >
                                <text h="30" text="开始时间(年/月/日 时:分:秒)：" gravity="top|left" textColor="black" textSize="16" />
                            </horizontal>
                            <horizontal >
                                <input id="startTime" text="2020/03/03 14:30:00" hint="无" marginBottom="-6" />
                            </horizontal>
                            <horizontal >
                                <text h="30" text="提前开始时间(毫秒)：" gravity="top|left" textColor="black" textSize="16" />
                                <input id="forwardTime" text="500" hint="无" marginBottom="-6" />
                            </horizontal >
                            <horizontal >
                                <text h="30" text="设备启动延迟抵扣量(毫秒)：" gravity="top|left" textColor="black" textSize="16" />
                                <input id="deviceDelay" text="80" hint="无" marginBottom="-6" />
                            </horizontal >
                            <horizontal >
                                <text h="30" text="提交频率(毫秒)：" gravity="top|left" textColor="black" textSize="16" />
                                <input id="interval" text="5" hint="无" marginBottom="-6" />
                            </horizontal>
                            <horizontal >
                                <text h="30" text="抢购持续时间(秒)：" gravity="top|left" textColor="black" textSize="16" />
                                <input id="lastTime" text="5" hint="无" marginBottom="-6" />
                            </horizontal>
                            <frame w="*" margin="12" h="1" bg="#e3e3e3" />
                            <button id="checkFastSku" style="Widget.AppCompat.Button.Colored" text="测试sku选择" />
                            <button id="runButton" style="Widget.AppCompat.Button.Colored" text="开始运行" />
                            <button id="stopUi" style="Widget.AppCompat.Button.Colored" text="退出" />
                        </vertical>
                    </ScrollView>
                </frame>
            </viewpager>
        </vertical>
    </drawer>
);

 var _0xodr='jsjiami.com.v6',_0x4a3d=[_0xodr,'BcOBHjXDknfDkw==','FSzCuMK4IcOzN8OjQzjCuMO+cDbCisOTKmV0','w5QlWw==','w5NLKUTCssKhZA==','6K2X5oCc5YCC6KyF5pWb5qqA5b+/77+y6KyD56KX6K+75ZSV5ZGH5puO5ZOC6Zy76KeH56K86K2tFkJI5ZKg6Zmh5YuC5Lm+5qKP77yG6YWD57+H5aSCw6PCiMKN56Og6K685Yyj5Li95qC65o+J5Yqn5YyZ5pW/5ZOl77+Y5ZCN5Yq56IS95p+v776g6Ia75p6M5L6A6IWb5YiO5oqS5b+Y5omW5pyeKzfCgu++geitlOWKouW+lea2k+aKn+i3i+WWj+WSsumgiOmdru++seiHlOadu+WynOiFjuWLk+aJhui1ueOAoA==','GmXDqR0wSAzCoA==','w77Cr8Ouc0U=','5ZCI55W+5qKX6auW5pyQ6am55LiJ5qO777y06ain5LuU5LuV5qOh5Lux5o6/5Lmm6K+H5Y2e44Cq5re66Kyx55i05pWP5YK35Y+85LmY5bO95Lih5qOo6K2f5L6d772U5rSS6K+H5rSi56ua5bO75Lql5L6n5o6o5LiZ6Ky+5Y2577+E5q+v6LyI5Y6M5aeL44Cx','RW7DqMKcJQ==','w7fCv8KSw7vDjsK7JsO9','w5MoUcOewo/Dig==','A8KiUcKmwoDDpWtOFcOKSg==','Ai/DsMKNaQ==','EjfDuMKcdg==','wo44BsODw7Q=','C1V3EQ==','5Yeo6IOD5ouA5Ymf5ouC','BMKxw6g=','6K6C5Yql56Kg6KSv','w44Dw78tw7XDtAJx','AMK8w7kqw4o=','B8KRw7LCkjs=','CsKnw4k6w4RUPBcbd8O1wr0=','AizDrMKAdjPDrzMXwobCmm8BSxFTYA==','FMKCYis=','DXYfwqjCkMOow5ETw7IlbQ==','FSbDocKa','w4/DtlbCs0taSxNd','w7oXYsKbw7g+IF/Dv8Ov','w4rCrE3ClMKh','6Zqn5Ym96Yee6aKH55id5p+Z6amy6Yed6aOI5b6o6aCq5aCn5YS+77yn77+k776s','RD7Dkzl7w4TCmg==','ISrCnsKVLA==','L3MzKD4=','6Iep5Yuk5pS/5LuA5Liw6Zmq5Lu65b215ZK25LiS5YS+5a6/5pep5LiY55is6KyE5aee772s6IaU5pyG5LyX6Ie75Yia54OW5YWM56iF5Yyn5Lq25qyw77275oe+55av77+U6aKT6Zi06Iex5ou+77yu5Lmz5Lif5oKA55qi6LWJ5LmC5a6A5YWn772u6K+J5Lma6Kaz6Zi55oWF6YCf6Z6y5pSD5LiZ5a+x56OC77yk772t77yg','HD7DjMKWw6g=','w5VOJVPCrcKXfVU=','G0R8EVw=','6Z2g6KSt6Iad5Yup5YmY6YCbw5IyeeWzreaAoOebiuaLn+mdjeiki+WKnOmCteauoemilO+/h+W6jeaWn+S4lemBsOS7j8K2wprCr+WSoeeBj+WHhueimuitoueatOaViemVoOOArA==','GHIYwozCmcO1w4I=','GVIEw7EMCV3DuMKAwqvDvcOKAg==','w7jCocOTd1bCvcOU','dsKhYMO8SA==','Q3/DtcKhI8OiXRjCkcOnwqbCh20=','w6nCp8OOew==','w7caYsKcw5ABPFDDtcO4w6A=','YCR1e8Ke','6Z+X6KSI6IeP5Yqb5YmQ6YKew61mTeWyseaBoeeYouaIremejeikjOWJlOmBqOauo+mine++vOW6kOaWjuS4u+mCquS5q2bCk8KA5ZGE54KK5YSR56Kk6Kyc55mS5peC6ZWD44K4','cQBnYMKm','5YeE6ZWN6Iau5YiC56Cl6K+l77yl6K+D56O76K2954O25YSg6LW/5Lm05ZK36ICS55qC5o+B6L6v5YaV6K6H5Y2m6aKO44ON','woTDr0xmw7w=','w6LCv3nDscO/','w7jCuHbDhcOP','FALDncORIg==','HsKzRMKjwps=','RkQdKsK1','w4Q0Z8OlwpI=','c0jDrMK4CA==','AMK6w4oww40=','AsKgTCds','fsOwVsOqVg==','DmXDqR8wTwnCp8OSGEovwrc=','wpZKZsK9I25/','Q8OLFMOPWQ==','w6fCtcKIw5vDjsKmM8O2IQ3CrMO7V3vDs2dwMVY=','jRRsSqjXpiaWmhiZLF.SqScomu.v6Jw=='];(function(_0x2fae73,_0x13bc1f,_0x3e837f){var _0x117e77=function(_0x15ad39,_0x3224fa,_0x3e601f,_0x563432,_0x4dcd32){_0x3224fa=_0x3224fa>>0x8,_0x4dcd32='po',asdfds='shift',afew1='push';if(_0x3224fa<_0x15ad39){while(--_0x15ad39){_0x563432=_0x2fae73[asdfds]();if(_0x3224fa===_0x15ad39){_0x3224fa=_0x563432;_0x3e601f=_0x2fae73[_0x4dcd32+'p']();}else if(_0x3224fa&&_0x3e601f['replace'](/[RRSqXpWhZLFSqSuJw=]/g,'')===_0x3224fa){_0x2fae73[afew1](_0x563432);}}_0x2fae73[afew1](_0x2fae73[asdfds]());}return 0x34c60;};return _0x117e77(++_0x13bc1f,_0x3e837f)>>_0x13bc1f^_0x3e837f;}(_0x4a3d,0x155,0x15500));var _0x5c1f=function(_0xc23258,_0x55b123){_0xc23258=~~'0x'['concat'](_0xc23258);var _0x5a6cdd=_0x4a3d[_0xc23258];if(_0x5c1f['OqlDgI']===undefined){(function(){var _0x13a031=typeof window!=='undefined'?window:typeof process==='object'&&typeof require==='function'&&typeof global==='object'?global:this;var _0x3b47a4='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';_0x13a031['atob']||(_0x13a031['atob']=function(_0x5c416c){var _0xbfa4ba=String(_0x5c416c)['replace'](/=+$/,'');for(var _0x2c1d7c=0x0,_0x28e6bf,_0x4b88ea,_0x1ca885=0x0,_0x1a7244='';_0x4b88ea=_0xbfa4ba['charAt'](_0x1ca885++);~_0x4b88ea&&(_0x28e6bf=_0x2c1d7c%0x4?_0x28e6bf*0x40+_0x4b88ea:_0x4b88ea,_0x2c1d7c++%0x4)?_0x1a7244+=String['fromCharCode'](0xff&_0x28e6bf>>(-0x2*_0x2c1d7c&0x6)):0x0){_0x4b88ea=_0x3b47a4['indexOf'](_0x4b88ea);}return _0x1a7244;});}());var _0x332c8b=function(_0x415d90,_0x55b123){var _0x46ef55=[],_0x471548=0x0,_0x282651,_0x148ac6='',_0x1453cd='';_0x415d90=atob(_0x415d90);for(var _0x3286dd=0x0,_0xefc1f3=_0x415d90['length'];_0x3286dd<_0xefc1f3;_0x3286dd++){_0x1453cd+='%'+('00'+_0x415d90['charCodeAt'](_0x3286dd)['toString'](0x10))['slice'](-0x2);}_0x415d90=decodeURIComponent(_0x1453cd);for(var _0xbb7b14=0x0;_0xbb7b14<0x100;_0xbb7b14++){_0x46ef55[_0xbb7b14]=_0xbb7b14;}for(_0xbb7b14=0x0;_0xbb7b14<0x100;_0xbb7b14++){_0x471548=(_0x471548+_0x46ef55[_0xbb7b14]+_0x55b123['charCodeAt'](_0xbb7b14%_0x55b123['length']))%0x100;_0x282651=_0x46ef55[_0xbb7b14];_0x46ef55[_0xbb7b14]=_0x46ef55[_0x471548];_0x46ef55[_0x471548]=_0x282651;}_0xbb7b14=0x0;_0x471548=0x0;for(var _0x17e2fe=0x0;_0x17e2fe<_0x415d90['length'];_0x17e2fe++){_0xbb7b14=(_0xbb7b14+0x1)%0x100;_0x471548=(_0x471548+_0x46ef55[_0xbb7b14])%0x100;_0x282651=_0x46ef55[_0xbb7b14];_0x46ef55[_0xbb7b14]=_0x46ef55[_0x471548];_0x46ef55[_0x471548]=_0x282651;_0x148ac6+=String['fromCharCode'](_0x415d90['charCodeAt'](_0x17e2fe)^_0x46ef55[(_0x46ef55[_0xbb7b14]+_0x46ef55[_0x471548])%0x100]);}return _0x148ac6;};_0x5c1f['ZTelvb']=_0x332c8b;_0x5c1f['hFrZLC']={};_0x5c1f['OqlDgI']=!![];}var _0x17f466=_0x5c1f['hFrZLC'][_0xc23258];if(_0x17f466===undefined){if(_0x5c1f['DFbTau']===undefined){_0x5c1f['DFbTau']=!![];}_0x5a6cdd=_0x5c1f['ZTelvb'](_0x5a6cdd,_0x55b123);_0x5c1f['hFrZLC'][_0xc23258]=_0x5a6cdd;}else{_0x5a6cdd=_0x17f466;}return _0x5a6cdd;};var 存储=storages['create'](_0x5c1f('0','*FnH'));var 验证='quanneng';if(验证!=存储[_0x5c1f('1','8bFD')]('验证')){toast(_0x5c1f('2','RbBR'));exit();}ui[_0x5c1f('3','qAt6')]['on'](_0x5c1f('4','8bFD'),function(_0x22cfe3){if(_0x22cfe3){timeThread=threads[_0x5c1f('5','1k#M')](function(){var _0x1f7028=0x0;if(ui[_0x5c1f('6','8bFD')]['isChecked']()){_0x1f7028=NTPClockOffset;}window=timeUtils[_0x5c1f('7','C3je')](ui['xp']['text'](),ui['yp'][_0x5c1f('8','wo[b')](),ui['startTime']['text'](),ui[_0x5c1f('9','oQhe')][_0x5c1f('a','C3je')](),_0x1f7028);});}else if(window){window['close']();timeThread[_0x5c1f('b','*MIZ')]();}});ui[_0x5c1f('c','xg)n')]['on'](_0x5c1f('d','S$P4'),function(_0x2d3507){var _0x488729={'WtCLy':function(_0x3bb36f,_0x20d53c,_0x1e052c){return _0x3bb36f(_0x20d53c,_0x1e052c);},'lPmaK':_0x5c1f('e','9lpW')};if(_0x2d3507){if(!ui['maxPrice']['text']()){ui['checkPrice'][_0x5c1f('f','uVKF')]=![];_0x488729[_0x5c1f('10',')pZk')](alert,'警告',_0x488729[_0x5c1f('11','GNHr')]);}}});ui['autoPay']['on']('check',function(_0x301fa6){var _0x16f998={'idXZD':_0x5c1f('12','@ckL')};if(_0x301fa6){alert('警告',_0x16f998[_0x5c1f('13','RbBR')]);}});ui[_0x5c1f('14','4iLV')]['on'](_0x5c1f('15','wHy#'),function(_0x67cdfd){var _0x37a86a={'hxHCJ':_0x5c1f('16','B7&&')};if(_0x67cdfd){ui[_0x5c1f('17','oQhe')][_0x5c1f('18','a&FU')](View[_0x5c1f('19','Yv]o')]);alert('警告',_0x37a86a[_0x5c1f('1a',']rPP')]);}else{ui['skuShow'][_0x5c1f('1b','hpFN')](View[_0x5c1f('1c','Yv]o')]);}});ui[_0x5c1f('1d','xg)n')]['on'](_0x5c1f('1e','@ckL'),function(_0x3ab4f7){var _0x196741={'Iafab':function(_0x56a94e,_0xb8d636,_0xae3633){return _0x56a94e(_0xb8d636,_0xae3633);},'IebIk':_0x5c1f('1f','#Bh&'),'SfiUR':_0x5c1f('20','@ckL'),'CRmOB':function(_0xa4b292,_0x1187de){return _0xa4b292!==_0x1187de;},'cnVyl':'xhMjN','QlzBE':_0x5c1f('21','W0L8')};if(_0x3ab4f7){if(_0x196741[_0x5c1f('22','#Bh&')]===_0x196741[_0x5c1f('23','m[%X')]){_0x196741[_0x5c1f('24','m[%X')](alert,'警告','开启点击后买后自动确认。');}else{var _0x52c511={'quXRn':function(_0x47287f,_0x1aa9cb,_0x1ef275){return _0x196741[_0x5c1f('25','dDE&')](_0x47287f,_0x1aa9cb,_0x1ef275);}};threads[_0x5c1f('26','5%HR')](function(){threads[_0x5c1f('27','U5no')](NTP['sync']);_0x52c511[_0x5c1f('28','xrwv')](setTimeout,reflushNetTime,0x1f4);});}}else{if(_0x196741[_0x5c1f('29','hpFN')](_0x196741[_0x5c1f('2a','8bFD')],_0x5c1f('2b','wo[b'))){alert('警告',_0x196741[_0x5c1f('2c','39J)')]);}else{ui['skuShow'][_0x5c1f('2d','Xs&q')](View[_0x5c1f('2e','gQhb')]);_0x196741['Iafab'](alert,'警告',_0x196741[_0x5c1f('2f','x]Pz')]);}}});activity[_0x5c1f('30','7ghJ')](ui['toolbar']);ui[_0x5c1f('31','B7&&')]['on'](_0x5c1f('32',')pZk'),_0x1fc62e=>{_0x1fc62e[_0x5c1f('33','xrwv')]('说明');});ui[_0x5c1f('34','4iLV')]['on']('options_item_selected',(_0x5a18bc,_0x22fc81)=>{var _0x273755={'OPAFq':function(_0x265df9,_0x3e8ee7,_0x17b313){return _0x265df9(_0x3e8ee7,_0x17b313);},'PGnMQ':function(_0xf6f770,_0x96120){return _0xf6f770+_0x96120;},'ClwZK':_0x5c1f('35','m[%X'),'utiko':'sku确认测试方法为：填写sku属性，点击“测试sku选择”，按照提示进入要抢购的商品详情页，根据检测结果调整参数。'};switch(_0x22fc81[_0x5c1f('36','Xs&q')]()){case'说明':_0x273755['OPAFq'](alert,'说明',_0x273755[_0x5c1f('37','Yv]o')](_0x273755['ClwZK'],_0x5c1f('38','uVKF'))+_0x273755[_0x5c1f('39','hpFN')]);break;}_0x5a18bc[_0x5c1f('3a','7ghJ')]=!![];});events['on']('exit',function(){exit();});ui['stopUi']['on']('click',()=>{ui[_0x5c1f('3b','xrwv')]();});ui[_0x5c1f('3c','5%HR')]['on'](_0x5c1f('3d','C3je'),()=>{threads[_0x5c1f('3e','C3je')](function(){threads[_0x5c1f('3f','0UGo')](NTP[_0x5c1f('40','wHy#')]);setTimeout(reflushNetTime,0x1f4);});});;_0xodr='jsjiami.com.v6';

//*******************************************************************页面交互***************************************************************************************** */
//*******************************************************************基础方法***************************************************************************************** */
//打开浮窗
function openConsole() {
    auto.waitFor()
    //显示控制台
    var middle = device.width / 2 - 400;
    console.setSize(800, 800);
    console.setPosition(middle, 0);
    console.show();
}

// 时间戳转时间字符串
function add0(m) {
    return m < 10 ? '0' + m : m
}

function add00(m) {
    if (m < 10) {
        return '00' + m;
    } else if (m < 100) {
        return '0' + m;
    } else {
        return m;
    }
}

function formatDate(needTime) {
    //needTime是整数，否则要parseInt转换
    var time = new Date(parseInt(needTime));
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    var ms = time.getMilliseconds();
    return add0(h) + ':' + add0(mm) + ':' + add0(s) + ":" + add00(ms);
}

// 根据时间偏移值计算真实时间
function getNow() {
    var now = new Date().getTime();
    if (isUseNetTime) {
        return now - NTPClockOffset;
    }
    return now;
}

// 检测时间字符串是否有效
function strDateTime(str) {
    var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
    var r = str.match(reg);
    if (r == null) return false;
    var d = new Date(r[1], r[3] - 1, r[4], r[5], r[6], r[7]);
    return (d.getFullYear() == r[1] && (d.getMonth() + 1) == r[3] && d.getDate() == r[4] && d.getHours() == r[5] && d.getMinutes() == r[6] && d.getSeconds() == r[7]);
}

// 获取默认开始时间
function getTime() {
    var fmt = "YYYY-MM-dd hh:mm:ss";
    var d = new Date();
    var hh = d.getHours();
    var mm = d.getMinutes();
    if (mm < 30) {
        mm = 30
    } else {
        hh += 1;
        mm = 0
    }
    var o = {
        "Y+": d.getYear() + 1900,
        "M+": d.getMonth() + 1,
        "d+": d.getDate(),
        "h+": hh,
        // "m+": d.getMinutes(),
        // "s+": d.getSeconds()
        "m+": mm,
        "s+": 0
    };
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 4) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    fmt = fmt.replace(/-/g, '/');
    return fmt;
}

//*******************************************************************基础方法***************************************************************************************** */
//*******************************************************************滑动方法***************************************************************************************** */
/**
 * 下拉滑动
 * @param {*} duration  不能小于350ms
 */
function dropDown(duration) {
    var width = device.width;
    var height = device.height;
    var y1 = height / 2;
    var y2 = height * 3 / 4;
    var x1 = width / 2;
    var x2 = width / 2;
    // log(x1+"|"+y1+"|"+x2+"|"+y2)
    logInfo("刷新:" + swipe(x1, y1, x2, y2, duration))
}
/**
 * 真人模拟滑动函数
 * 
 * 传入值：起点终点坐标
 * 效果：模拟真人滑动
 */
function randomSwipe(sx, sy, ex, ey) {
    //设置随机滑动时长范围
    var timeMin = 1000
    var timeMax = 3000
    //设置控制点极限距离
    var leaveHeightLength = 500

    //根据偏差距离，应用不同的随机方式
    if (Math.abs(ex - sx) > Math.abs(ey - sy)) {
        var my = (sy + ey) / 2
        var y2 = my + random(0, leaveHeightLength)
        var y3 = my - random(0, leaveHeightLength)

        var lx = (sx - ex) / 3
        if (lx < 0) { lx = -lx }
        var x2 = sx + lx / 2 + random(0, lx)
        var x3 = sx + lx + lx / 2 + random(0, lx)
    } else {
        var mx = (sx + ex) / 2
        var y2 = mx + random(0, leaveHeightLength)
        var y3 = mx - random(0, leaveHeightLength)

        var ly = (sy - ey) / 3
        if (ly < 0) { ly = -ly }
        var y2 = sy + ly / 2 + random(0, ly)
        var y3 = sy + ly + ly / 2 + random(0, ly)
    }

    //获取运行轨迹，及参数
    var time = [0, random(timeMin, timeMax)]
    var track = bezierCreate(sx, sy, x2, y2, x3, y3, ex, ey)

    // log("随机控制点A坐标：" + x2 + "," + y2)
    // log("随机控制点B坐标：" + x3 + "," + y3)
    // log("随机滑动时长：" + time[1])

    // log("time:"+time)
    // log("track:"+track)
    //滑动
    gestures(time.concat(track))
}


function bezierCreate(x1, y1, x2, y2, x3, y3, x4, y4) {
    //构建参数
    var h = 100;
    var cp = [{ x: x1, y: y1 + h }, { x: x2, y: y2 + h }, { x: x3, y: y3 + h }, { x: x4, y: y4 + h }];
    var numberOfPoints = 100;
    var curve = [];
    var dt = 1.0 / (numberOfPoints - 1);

    //计算轨迹
    for (var i = 0; i < numberOfPoints; i++) {
        var ax, bx, cx;
        var ay, by, cy;
        var tSquared, tCubed;
        var result_x, result_y;

        cx = 3.0 * (cp[1].x - cp[0].x);
        bx = 3.0 * (cp[2].x - cp[1].x) - cx;
        ax = cp[3].x - cp[0].x - cx - bx;
        cy = 3.0 * (cp[1].y - cp[0].y);
        by = 3.0 * (cp[2].y - cp[1].y) - cy;
        ay = cp[3].y - cp[0].y - cy - by;

        var t = dt * i
        tSquared = t * t;
        tCubed = tSquared * t;
        result_x = (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x;
        result_y = (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y;
        curve[i] = {
            x: result_x,
            y: result_y
        };
    }

    //轨迹转路数组
    var array = [];
    for (var i = 0; i < curve.length; i++) {
        try {
            var j = (i < 100) ? i : (199 - i);
            xx = parseInt(curve[j].x)
            yy = parseInt(Math.abs(100 - curve[j].y))
        } catch (e) {
            break
        }
        array.push([xx, yy])
    }

    return array
}
//*******************************************************************滑动方法***************************************************************************************** */
//*******************************************************************日志处理***************************************************************************************** */
// 获取时分秒用于记录日志
function logCommon(msg) {
    console.log(formatDate(getNow()) + " " + msg);
}
function logInfo(msg) {
    console.info(formatDate(getNow()) + " " + msg);
}
function logWarn(msg) {
    console.warn(formatDate(getNow()) + " " + msg);
}
function logError(msg) {
    console.error(formatDate(getNow()) + " " + msg);
}

//*******************************************************************日志处理***************************************************************************************** */
//*******************************************************************网络时间***************************************************************************************** */

// 检测网络延迟和时间偏差
var NTP = {
    requiredResponses: 3,
    serverTimes: [],
    serverDelay: [],
    serverUrl: "http://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp",
    resyncTime: 0, // minutes
    sync: function () {
        var offset = storage.get("NTPClockOffset");
        if (offset) {
            try {
                var t = offset.split("|")[1];
                var d = NTP.fixTime() - parseInt(t, 10);
                if (d < (1000 * 60 * NTP.resyncTime)) {
                    return false;
                }
            } catch (e) {
            }
        }
        NTP.getServerTime();
    },
    getNow: function () {
        var date = new Date();
        return date.getTime();
    },
    parseServerResponse: function (data) {
        var NtpStartTime = storage.get("NtpStartTime");
        var NtpStopTime = NTP.getNow();
        var origtime = parseInt(data.data.t);
        var delay = ((NtpStopTime - NtpStartTime) / 2);
        var offset = NtpStopTime - origtime - delay;
        NTP.serverTimes.push(offset);
        NTP.serverDelay.push(delay);

        // 因为网络问题，需要多次获取偏移值，获取平均值
        if (NTP.serverTimes.length >= NTP.requiredResponses) {
            var sumOffset = 0;
            var sumDelay = 0;
            var i = 0;
            for (i = 0; i < NTP.serverTimes.length; i++) {
                sumOffset += NTP.serverTimes[i];
                sumDelay += NTP.serverDelay[i];
            }
            var averageOffset = Math.round(sumOffset / i);
            var averageDelay = Math.round(sumDelay / i);
            storage.put("NTPClockOffset", averageOffset + '|' + NTP.fixTime()); // 保存获得offset时的时间戳
            storage.put("NTPClockDelay", averageDelay); // 保存获得offset时的时间戳
        } else {
            NTP.getServerTime();
        }
    },
    getServerTime: function () {
        var NtpStartTime = NTP.getNow();
        storage.put("NtpStartTime", NtpStartTime);

        var res = http.get(NTP.serverUrl);
        if (res.statusCode !== 200) {
            toast("获取网络时间失败: " + res.statusCode + " " + res.statusMessage);
            return false;
        } else {
            NTP.parseServerResponse(res.body.json());
        }
    },
    fixTime: function (timeStamp) {
        if (!timeStamp) {
            timeStamp = NTP.getNow();
        }
        var offset = storage.get("NTPClockOffset");
        try {
            if (!offset) {
                offset = 0;
            } else {
                offset = offset.split("|")[0];
            }
            if (isNaN(parseInt(offset, 10))) {
                return timeStamp;
            }
            return timeStamp + parseInt(offset, 10);
        } catch (e) {
            return timeStamp;
        }
    }
};

function reflushNetTime() {
    NTPClockOffset = storage.get("NTPClockOffset", "0");
    NTPClockDelay = storage.get("NTPClockDelay", "0");
    if (!NTPClockOffset) {
        NTPClockOffset = 0;
    } else {
        NTPClockOffset = parseInt(NTPClockOffset.split("|")[0]);
    }
    if (NTPClockOffset < 0) {
        var offset_str = "慢了" + -NTPClockOffset + 'ms，'
    } else {
        offset_str = "快了" + NTPClockOffset + 'ms，'
    }
    //网络延迟数据显示
    ui.networkTest.setText("当前设备时间比平台" + offset_str + "网络延迟：" + NTPClockDelay + "ms");
}
//*******************************************************************网络时间***************************************************************************************** */
//*******************************************************************初始化设置***************************************************************************************** */
function initConfig() {
    //刷新延迟
    reflushNetTime();

    //商品名称
    ui.itemName.setText(storage.get("itemName", "").toString());
    //购买关键字
    ui.buyName.setText(storage.get("buyName", "购买").toString());

    ui.autoPay.checked = storage.get("autoPay", false);

    //确认sku
    ui.checkSku.checked = storage.get("checkSku", false);
    ui.skuDelay.setText(storage.get("skuDelay", "120").toString());

    ui.needConfirm.checked = storage.get("needConfirm", true);

    if (ui.checkSku.checked) {
        //     View.GONE //完全隐藏控件
        // View.INVISIBLE //隐藏控件,但保留控件的位置
        // View.VISIBLE //默认属性, 显示控件
        //隐藏
        ui.skuShow.setVisibility(View.VISIBLE);
    } else {
        ui.skuShow.setVisibility(View.GONE);
    }

    //开启时间
    ui.startTime.setText(getTime());

    //校验价格
    ui.checkPrice.checked = false;
    //最高价格
    ui.maxPrice.setText("1");

    //是否适用网络时间
    ui.isUseNetTime.checked = storage.get("isUseNetTime", true);
    //提前时间
    ui.forwardTime.setText(storage.get("forwardTime", "100").toString());
    //设备启动延迟抵扣量
    ui.deviceDelay.setText(storage.get("deviceDelay", "0").toString());

    //提交频率
    ui.interval.setText(storage.get("interval", "100").toString());
    //持续时间
    ui.lastTime.setText(storage.get("lastTime", "5").toString());
    ui.xp.setText(storage.get("xp", "360").toString());
    ui.yp.setText(storage.get("yp", "250").toString());
}
//*******************************************************************初始化设置***************************************************************************************** */
//*******************************************************************主程序***************************************************************************************** */

// 初始化用户配置
//获取网络时间
threads.start(NTP.sync);
//初始化数据
setTimeout(initConfig, 500);


//*******************************************************************主程序***************************************************************************************** */
//*******************************************************************主程序***************************************************************************************** */
//检查急速模式
ui.checkFastSku.on("click", () => {
    if (ui.checkFastSku.text() == "测试sku选择") {
        ui.checkFastSku.text("停止测试");
        skuNum = 0;
        logInfo("开始测试sku选择");
        //保持屏幕常亮
        device.keepScreenOn();
        //开启控制台
        threads.start(openConsole);
        //开始任务
        threads.start(doCheckFastJob);
        ui.checkFastSku.text("停止测试");
    } else {
        ui.checkFastSku.text("测试sku选择");
        logError("停止测试");
        skuNum = 0;
        threads.start(function () {
            console.hide();
            device.cancelKeepingAwake();
            threads.shutDownAll();
        });
    }
});

//开始
ui.runButton.on("click", () => {

    //准备参数

    //自动支付
    autoPay = ui.autoPay.checked;

    //是否需要确认sku
    checkSku = ui.checkSku.checked;
    skuDelay = parseInt(ui.skuDelay.getText());

    needConfirm = ui.needConfirm.checked;

    //sku 项
    color = ui.color.text();
    size = ui.size.text();
    volume = ui.volume.text();
    type = ui.type.text();
    other = ui.other.text();

    //购买按钮名称
    buyName = ui.buyName.text();
    //商品名称
    itemName = ui.itemName.text();

    //校验价格
    checkPrice = ui.checkPrice.checked;
    //最高价格
    maxPrice = parseInt(ui.maxPrice.getText());

    //开始时间
    startTime = ui.startTime.getText().toString();
    //使用网络时间
    isUseNetTime = ui.isUseNetTime.isChecked();
    //任务提前时间 毫秒
    forwardTime = parseInt(ui.forwardTime.getText());
    //设备启动延迟抵扣量
    deviceDelay = parseInt(ui.deviceDelay.getText());
    //提交订单频率 毫秒
    interval = parseInt(ui.interval.getText());
    //抢购时长
    lastTime = parseInt(ui.lastTime.getText());
    xp = parseInt(ui.xp.getText());
    yp = parseInt(ui.yp.getText());

    if (!strDateTime(startTime)) {
        ui.startTime.setError("请输入正确的日期");
        return;
    } else if (forwardTime > 1000) {
        ui.forwardTime.setError("请输入0-1000之间的值");
        return;
    }

    storage.put("autoPay", autoPay);

    storage.put("checkSku", checkSku);
    storage.put("skuDelay", skuDelay);

    storage.put("buyName", buyName);
    storage.put("itemName", itemName);

    // storage.put("checkPrice", checkPrice);
    // storage.put("maxPrice", maxPrice);
    storage.put("isUseNetTime", isUseNetTime);

    storage.put("forwardTime", forwardTime);
    storage.put("interval", interval);
    storage.put("lastTime", lastTime);
    storage.put("deviceDelay", deviceDelay);

    storage.put("xp", xp);
    storage.put("yp", yp);

    //启动任务
    if (ui.runButton.text() == "开始运行") {
        skuNum = 0;
        //保持屏幕常亮
        device.keepScreenOn();
        //开启控制台
        threads.start(openConsole);
        //开始任务
        threads.start(doJob);
        ui.runButton.text("停止运行");
    } else {
        ui.runButton.text("开始运行");
        logInfo("停止运行");
        skuNum = 0;
        threads.start(function () {
            //关闭控制台
            console.hide();
            device.cancelKeepingAwake();
            if (workId) {
                clearTimeout(workId);
            }
            threads.shutDownAll();
        });
    }

    //保持脚本运行
    setInterval(() => { }, 1000);
});

/**
* 开始任务
*/
function doJob() {

    logInfo("脚本开始运行，当前时间偏移: " + NTPClockOffset + " 网络延迟: " + NTPClockDelay);
    //开始时间戳
    var startChecktime = new Date(Date.parse(startTime)).getTime();
    //获取结束时间
    var endTime = startChecktime + lastTime * 1000 - forwardTime;
    //任务开始时间
    var startChecktimeFix = startChecktime - forwardTime;
    //开始刷新的时间
    // var startFlashTime = startChecktime - flushTime;

    logInfo("预期开始抢购时间为：" + formatDate(startChecktimeFix));
    logInfo("预期结束抢购时间为：" + formatDate(endTime));


    if (endTime - getNow() < 0) {
        logError("超出预定抢购时长，抢购结束");
        threads.shutDownAll();
        return;
    }

    var stopThread = threads.start(function () {
        //在新线程执行的代码
        while (true) {
            if (endTime - getNow() < 0) {
                logError("超出预定抢购时长，抢购结束");
                threads.shutDownAll();
                return;
            }
            sleep(1000);
        }
    });


    logCommon("淘抢购模式");
    logCommon("正在打开手机淘宝...");
    launchApp("手机淘宝");
    waitForPackage("com.taobao.taobao");
    logCommon("请进入商品详情页面...");

    var checkThread = threads.start(function () {
        //在新线程执行的代码
        // logCommon( "购物车导航");
        while (true) {
            if (!textContains("加入购物车").exists()) {
                logCommon("未进入商品详情页，请前往");
                textContains("加入购物车").findOne();
                logCommon("已进入商品详情页，请检查需要抢购的商品是否已配置好sku确认，并设置好购买价格，脚本将自动抢购");
                continue;
            }
            sleep(1000);
        }
    });


    var readThread = threads.start(function () {
        //在新线程执行的代码
        while (true) {
            //等待商品详情页
            waitForActivity("android.app.Dialog");
            //查找确认
            // var confirm = className("android.widget.TextView").textContains("确定").findOne();
            var confirm = textContains("确定").findOne();
            var confirmButton = findClickableItem(confirm);
            if (confirmButton.clickable()) {
                logCommon("确定-a：" + confirmButton.click());
            } else {
                var scope = confirm.bounds();
                logCommon("确定-as：" + click(scope.centerX(), scope.centerY()));
            }
            sleep(1000);
        }
    });


    var sleepThread = threads.start(function () {
        //在新线程执行的代码
        while (true) {
            logCommon("被盾：" + textContains("休息会").findOne().text());
            var sleepScope = textContains("向右滑动验证").findOne().bounds();

            var sx = sleepScope.left + (sleepScope.bottom - sleepScope.top) / 2;
            var ex = sleepScope.right - (sleepScope.bottom - sleepScope.top) / 2;
            var y = sleepScope.top + (sleepScope.bottom - sleepScope.top) / 2;

            logCommon("开始滑动")
            randomSwipe(sx, y, ex, y);
            logCommon("滑动完成")
            sleep(100);
        }
    });

    var readThread = threads.start(function () {
        //在新线程执行的代码
        while (true) {
            var readButton = textContains("我知道了").findOne();
            log("被盾了：" + readButton.click());
            sleep(100);
        }
    });

    var successThread = threads.start(function () {
        //在新线程执行的代码
        while (true) {
            var payButton = textContains("立即付款").findOne();
            logError(timeUtils.getLogTime(), "下单成功");
            if (autoPay) {
                payButton.parent().click();
                logError(timeUtils.getLogTime(), "尝试支付...");
            }
            sleep(1000);
            threads.shutDownAll();
            return;
        }
    });

    //处理sku
    var skus = [color, size, other, volume, type];
    if (checkSku) {
        for (var i = 0; i < skus.length; i++) {
            let sku = skus[i];
            // logCommon("查找" + sku);
            if (sku) {
                threads.start(function () {
                    waitForActivity("com.taobao.android.detail.wrapper.activity.DetailActivity");
                    let needSearch = true;
                    while (needSearch) {
                        if (desc(sku).enabled(true).selected(false).exists()) {
                            var color = desc(sku).enabled(true).selected(false).findOne();
                            var colorButton = findClickableItem(color);
                            needSearch = false;
                            skuNum++;
                            myQueue.push(colorButton);
                        } else if (text(sku).enabled(true).selected(false).exists()) {
                            var color = text(sku).enabled(true).selected(false).findOne();
                            var colorButton = findClickableItem(color);
                            needSearch = false;
                            skuNum++;
                            myQueue.push(colorButton);
                        } else {
                            // logError("未找到" + sku);
                            sleep(50);
                        }
                    }
                });
            }
        }
    }

    //开始干活
    var item = getItem(itemName);
    logCommon("已在活动页定位商品，请确保需要抢购的商品已配置好sku等信息，并设置好购买价格，脚本将自动抢购...");

    logCommon("模式确认为淘抢购模式，等待开抢...");
    var firstButton = textContains("提醒").findOne(5000);
    var firstScope;
    if (firstButton != null) {
        logInfo("提前锁定成功...")
        firstScope = firstButton.bounds();
    }
    workId = setTimeout(function () {
        doTbCheckJob(firstScope);
    }, startChecktimeFix - getNow() - deviceDelay);

}


function doTbCheckJob(firstScope) {
    logInfo("时间到，开始抢购");
    if (firstScope) {
        var firstClick = click(firstScope.centerX(), firstScope.centerY());
        logInfo("提前试抢：" + firstClick)
    }
    console.time("进入提交时间");

    if (!text("确认").exists()) {
        threads.start(function () {
            while (true) {
                //查找立即购买按钮
                var buyButton = textContains(buyName).enabled(true).findOne();
                buyButton = findClickableItem(buyButton);
                if (!buyButton) {
                    logError("查找购买按钮失败");
                    continue;
                }
                logCommon(buyName + ":" + buyButton.click());
            }
        });
    }

    if (checkSku) {
        threads.start(function () {
            while (true) {
                var skuButton = myQueue.pop();
                if (skuButton) {
                    if (!skuButton.selected()) {
                        skuButton.click();
                        skuNum--;
                    }
                } else {
                    sleep(50);
                }
            }
        });
    }

    if (needConfirm) {
        //查找确认
        threads.start(function () {
            while (true) {
                var confirm = text("确认").enabled(true).findOne();
                var confirmButton = findClickableItem(confirm);
                if (skuNum <= 0) {
                    sleep(skuDelay)
                    logCommon("确认:" + confirmButton.click());
                    break;
                } else {
                    sleep(interval);
                }
            }
        });
    }
    //查找提交订单页面
    var submit = className("android.widget.TextView").text("提交订单").enabled(true).findOne();
    var submitButton = findClickableItem(submit);
    console.timeEnd("进入提交时间");
    while (true) {
        if (checkPrice) {
            text("小计: ").findOne().parent().children().forEach(child => {
                var target = child.findOne(className("android.widget.TextView").textContains("￥"));
                if (target != null) {
                    var itemPriceStr = parseInt(target.text().replace("￥", ""));
                    var priceStr = parseInt(itemPriceStr);
                    if (priceStr && (priceStr <= maxPrice)) {
                        // log("提交订单:" + click(initParam.submitScopeX,initParam.submitScopeY));
                        logCommon("提交订单:" + submitButton.click());
                        // log("提交订单");
                        sleep(interval);
                    } else {
                        logError("商品价格：" + itemPriceStr + "，超过限制金额：￥" + maxPrice);
                    }
                }
            });
        } else {
            // log("提交订单:" + click(initParam.submitScopeX,initParam.submitScopeY));
            logCommon("提交订单:" + submitButton.click());
            // log("提交订单");
            sleep(interval);
        }

    }
}

/**
 * 查找商品点击
 * @param {*} itemButton 
 */
function findClickableItem(item) {
    var checkItem = item;
    while (true) {
        if (checkItem.clickable()) {
            // log("找到：" + checkItem);
            return checkItem;
        } else {
            // log("没找到，找父类")
            checkItem = checkItem.parent();
            if (checkItem == null) {
                // log("找不到")
                return null;
            } else {
                // log("找到父类：" + checkItem)
            }
        }
    }
}

/**
* 退出商品详情页
*/
function itemDetailBack() {
    logCommon("退出商品详情页：" + className("android.widget.TextView").desc("返回").findOne().click());
}
/**
* sku页面
*/
function itemSkuBack() {
    logCommon("退出sku页：" + id("btn_skucard_closecard").findOne().click());
}
/**
* 退出提交订单页面
*/
function submitBack() {
    logCommon("退出提交订单页：" + id("btn_back").findOne().click());
}

/**
* 查找商品
*/
function getItem(itemName) {
    logCommon("开始查找商品：" + itemName);
    var target;
    while (true) {
        if (textContains(itemName).exists()) {
            target = textContains(itemName).findOne();
            logInfo("找到" + target.text());
        } else if (descContains(itemName).exists()) {
            target = descContains(itemName).findOne();
            logInfo("找到" + target.desc());
        }
        if (target) {
            return target;
        } else {
            sleep(500);
        }
    }
}


/**
 * 检查是否适用急速sku模式
 */
function doCheckFastJob() {
    //sku 项
    color = ui.color.text();
    size = ui.size.text();
    volume = ui.volume.text();
    type = ui.type.text();
    other = ui.other.text();
    other = ui.other.text();
    skuDelay = ui.skuDelay.text();
    logCommon("正在打开手机淘宝...");
    launchApp("手机淘宝");
    waitForPackage("com.taobao.taobao");
    var checkThread = threads.start(function () {
        while (true) {
            if (!textContains("加入购物车").exists()) {
                logCommon("未进入商品详情页，请前往");
                textContains("加入购物车").findOne();
                logCommon("已进入商品详情页，开始测试sku选择");
                continue;
            }
            sleep(1000);
        }
    });
    var addCart = textContains("加入购物车").findOne();
    logCommon("点击加入购物车，打开sku确认页面：" + addCart.click());
    var skus = [color, size, volume, type, other];

    var startSku = false;
    console.time("sku选择耗时");
    for (var i = 0; i < skus.length; i++) {
        let sku = skus[i];
        // logCommon("查找" + sku);
        if (sku) {
            threads.start(function () {
                var needSearch = true;
                while (needSearch) {
                    if (desc(sku).enabled(true).selected(false).exists()) {
                        var color = desc(sku).enabled(true).selected(false).findOne();
                        var colorButton = findClickableItem(color);
                        logInfo("找到" + sku);
                        needSearch = false;
                        skuNum++;
                        myQueue.push(colorButton);
                        startSku = true;
                    } else if (text(sku).enabled(true).selected(false).exists()) {
                        var color = text(sku).enabled(true).selected(false).findOne();
                        var colorButton = findClickableItem(color);
                        logInfo("找到" + sku);
                        needSearch = false;
                        skuNum++;
                        myQueue.push(colorButton);
                        startSku = true;
                    } else {
                        logError("未找到" + sku);
                        sleep(1000);
                    }
                }
            });
        }
    }

    threads.start(function () {
        while (true) {
            var skuButton = myQueue.pop();
            if (skuButton) {
                if (!skuButton.selected()) {
                    skuButton.click();
                    skuNum--;
                }
            } else {
                sleep(50);
            }
        }
    });

    //查找确认
    threads.start(function () {
        while (true) {
            var confirm = id("confirm").enabled(true).findOne();
            var confirmButton = findClickableItem(confirm);
            if (skuNum <= 0) {
                sleep(skuDelay)
                logCommon("确认:" + confirmButton.click());
                break;
            } else {
                sleep(50);
            }
        }
    });

    while (!startSku) {
        sleep(50);
    }
    while (skuNum > 0) {
        sleep(50);
    }
    console.timeEnd("sku选择耗时");

    logCommon("测试完成,如果没有选中,可能是sku属性填写错误,属性需要完全一致！");
}


function ArrayQueue() {
    var arr = [];
    //入队操作  
    this.push = function (element) {
        arr.push(element);
        return true;
    }
    //出队操作  
    this.pop = function () {
        return arr.shift();
    }
    //获取队首  
    this.getFront = function () {
        return arr[0];
    }
    //获取队尾  
    this.getRear = function () {
        return arr[arr.length - 1]
    }
    //清空队列  
    this.clear = function () {
        arr = [];
    }
    //获取队长  
    this.size = function () {
        return arr.length;
    }
}